$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_zjhs_m")
    const dgrid1 = $NG.getCmpApi("p_form_zjhs_d1")
    const dgrid2 = $NG.getCmpApi("p_form_zjhs_d2")
    const getHeadValue = (str) => mstform.getItem(str).getValue()
    selectTabs()

    useValuesChange(() => {
        getXmkInfoByPhid()
    }, "p_form_zjhs_m.u_xmmc")

    useValuesChange(()=>{
        selectTabs()
    },"p_form_zjhs_m.u_cgxs")

    useUpdateRows(({args})=>{
        const datas = {}
        const rows = args[0]
        const keys = ['u_bnyhske','u_bnyhske1','u_bnhke','u_bnfxe','u_bnyyjlr','u_bnfhe','u_xnjhhge','u_bnyhge']
        rows.forEach(el=>{
            keys.forEach(key=>{
                if(!datas[key]){
                    datas[key] = (Number(el[key]) || 0)
                } else {
                    datas[key] += (Number(el[key]) || 0)
                }
            })
        })
        console.log(`编辑2`,datas);
        mstform.getItem("u_ljyhszjze").setValue(datas.u_bnyhske)
        mstform.getItem("u_ljhszjze").setValue(datas.u_bnyhske1)
        mstform.getItem("u_ljhbe").setValue(datas.u_bnhke)
        mstform.getItem("u_ljfxe").setValue(datas.u_bnfxe)
        mstform.getItem("u_ljyyjlr").setValue(datas.u_bnyyjlr)
        mstform.getItem("u_ljfhe").setValue(datas.u_bnfhe)
        mstform.getItem("u_ljjhhge").setValue(datas.u_xnjhhge)
        mstform.getItem("u_ljhge").setValue(datas.u_bnyhge)
    },"p_form_zjhs_d2")


        useUpdateRows(({args})=>{
        const datas = {}
        const rows = args[0]
        const keys = ["u_bnyyjlr","u_bnfhe","u_xnjhhge","u_bnyhge"]
        rows.forEach(el=>{
            keys.forEach(key=>{
                if(!datas[key]){
                    datas[key] = (Number(el[key]) || 0)
                } else {
                    datas[key] += (Number(el[key]) || 0)
                }
            })
        })
        console.log(`编辑1`,datas);
        mstform.getItem("u_ljyyjlr").setValue(datas.u_bnyyjlr)
        mstform.getItem("u_ljfhe").setValue(datas.u_bnfhe)
        mstform.getItem("u_ljjhhge").setValue(datas.u_xnjhhge)
        mstform.getItem("u_ljhge").setValue(datas.u_bnyhge)
    },"p_form_zjhs_d1")

    function selectTabs() {
        const u_cgxs = getHeadValue("u_cgxs")
        let hidden = true
        let tab = ""
        if(u_cgxs == '02'){
            tab = "tabPanel_tabItem"
        } else if(u_cgxs == '03'){
            hidden = false
            tab = "tabPanel_tabItem_1"
        } else {
            hidden = false
        }
        const tabs = $NG
            .getCompMap()
            .get("__Tabs__")[0]
            .getApi();
        // tabPanel_tabItem 参股 tabPanel_tabItem_1 控股
        tabs.updateItems((innerItems, activeKey) => {
            return [...innerItems.filter((item) => {
                if(item.name == tab){
                    return item
                }
            })];
        });
        tabs.setActiveKey(tab)
        const hideKey = ['u_zyhklx','u_ljhszjze','u_ykfx','u_ykfx','u_ljfxe']
        hideKey.forEach(item=>{
            mstform.getItem(item).setProps({
                hidden
            })
        })
    }
})
